home *** CD-ROM | disk | FTP | other *** search
- package com.sun.java.swing;
-
- import com.sun.java.accessibility.Accessible;
- import com.sun.java.accessibility.AccessibleContext;
- import com.sun.java.swing.plaf.SplitPaneUI;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Graphics;
- import java.awt.LayoutManager;
-
- public class JSplitPane extends JComponent implements Accessible {
- public static final int VERTICAL_SPLIT = 0;
- public static final int HORIZONTAL_SPLIT = 1;
- public static final String LEFT = "left";
- public static final String RIGHT = "right";
- public static final String TOP = "top";
- public static final String BOTTOM = "bottom";
- public static final String DIVIDER = "divider";
- public static final String ORIENTATION_PROPERTY = "orientation";
- public static final String CONTINUOUS_LAYOUT_PROPERTY = "continuousLayout";
- public static final String DIVIDER_SIZE_PROPERTY = "dividerSize";
- public static final String ONE_TOUCH_EXPANDABLE_PROPERTY = "oneTouchExpandable";
- public static final String LAST_DIVIDER_LOCATION_PROPERTY = "lastDividerLocation";
- protected int orientation;
- protected boolean continuousLayout;
- protected Component leftComponent;
- protected Component rightComponent;
- protected int dividerSize;
- protected boolean oneTouchExpandable;
- protected int lastDividerLocation;
-
- public JSplitPane() {
- this(1, false, new JButton("left button"), new JButton("right button"));
- }
-
- public JSplitPane(int newOrientation) {
- this(newOrientation, false);
- }
-
- public JSplitPane(int newOrientation, Component newLeftComponent, Component newRightComponent) {
- this(newOrientation, false, newLeftComponent, newRightComponent);
- }
-
- public JSplitPane(int newOrientation, boolean newContinuousLayout) {
- this(newOrientation, newContinuousLayout, (Component)null, (Component)null);
- }
-
- public JSplitPane(int newOrientation, boolean newContinuousLayout, Component newLeftComponent, Component newRightComponent) {
- ((Container)this).setLayout((LayoutManager)null);
- this.orientation = newOrientation;
- if (this.orientation != 1 && this.orientation != 0) {
- throw new IllegalArgumentException("cannot create JSplitPane, orientation must be one of JSplitPane.HORIZONTAL_SPLIT or JSplitPane.VERTICAL_SPLIT");
- } else {
- this.continuousLayout = newContinuousLayout;
- if (newLeftComponent != null) {
- this.setLeftComponent(newLeftComponent);
- }
-
- if (newRightComponent != null) {
- this.setRightComponent(newRightComponent);
- }
-
- this.updateUI();
- }
- }
-
- protected void addImpl(Component comp, Object constraints, int index) {
- if (constraints != null && !(constraints instanceof String)) {
- throw new IllegalArgumentException("cannot add to layout: constraint must be a string (or null)");
- } else {
- if (constraints == null) {
- if (this.getLeftComponent() == null) {
- constraints = "left";
- } else if (this.getRightComponent() == null) {
- constraints = "right";
- }
- }
-
- if (constraints == null || !constraints.equals("left") && !constraints.equals("top")) {
- if (constraints != null && (constraints.equals("right") || constraints.equals("bottom"))) {
- Component var5 = this.getRightComponent();
- if (var5 != null) {
- this.remove(var5);
- }
-
- this.rightComponent = comp;
- index = -1;
- } else if (constraints != null && constraints.equals("divider")) {
- index = -1;
- }
- } else {
- Component toRemove = this.getLeftComponent();
- if (toRemove != null) {
- this.remove(toRemove);
- }
-
- this.leftComponent = comp;
- index = -1;
- }
-
- super.addImpl(comp, constraints, index);
- }
- }
-
- public AccessibleContext getAccessibleContext() {
- if (super.accessibleContext == null) {
- super.accessibleContext = new AccessibleJSplitPane(this);
- }
-
- return super.accessibleContext;
- }
-
- public Component getBottomComponent() {
- return this.rightComponent;
- }
-
- public int getDividerLocation() {
- SplitPaneUI ui = this.getUI();
- return ui != null ? ui.getDividerLocation() : -1;
- }
-
- public int getDividerSize() {
- return this.dividerSize;
- }
-
- public int getLastDividerLocation() {
- return this.lastDividerLocation;
- }
-
- public Component getLeftComponent() {
- return this.leftComponent;
- }
-
- public int getMaximumDividerLocation() {
- SplitPaneUI ui = this.getUI();
- return ui != null ? ui.getMaximumDividerLocation() : -1;
- }
-
- public int getMinimumDividerLocation() {
- SplitPaneUI ui = this.getUI();
- return ui != null ? ui.getMinimumDividerLocation() : -1;
- }
-
- public int getOrientation() {
- return this.orientation;
- }
-
- public Component getRightComponent() {
- return this.rightComponent;
- }
-
- public Component getTopComponent() {
- return this.leftComponent;
- }
-
- public SplitPaneUI getUI() {
- return (SplitPaneUI)super.ui;
- }
-
- public String getUIClassID() {
- return "SplitPaneUI";
- }
-
- public boolean isContinuousLayout() {
- return this.continuousLayout;
- }
-
- public boolean isOneTouchExpandable() {
- return this.oneTouchExpandable;
- }
-
- protected void paintChildren(Graphics g) {
- super.paintChildren(g);
- SplitPaneUI ui = this.getUI();
- if (ui != null) {
- Graphics tempG = g.create();
- ui.finishedPaintingChildren(this, tempG);
- tempG.dispose();
- }
-
- }
-
- public void remove(int index) {
- Component comp = ((Container)this).getComponent(index);
- if (comp == this.leftComponent) {
- this.leftComponent = null;
- } else if (comp == this.rightComponent) {
- this.rightComponent = null;
- }
-
- super.remove(index);
- }
-
- public void remove(Component component) {
- if (component == this.leftComponent) {
- this.leftComponent = null;
- } else if (component == this.rightComponent) {
- this.rightComponent = null;
- }
-
- super.remove(component);
- }
-
- public void removeAll() {
- this.leftComponent = this.rightComponent = null;
- super.removeAll();
- }
-
- public void resetToPreferredSizes() {
- SplitPaneUI ui = this.getUI();
- if (ui != null) {
- ui.resetToPreferredSizes();
- }
-
- }
-
- public void setBottomComponent(Component comp) {
- this.setRightComponent(comp);
- }
-
- public void setContinuousLayout(boolean newContinuousLayout) {
- boolean oldCD = this.continuousLayout;
- this.continuousLayout = newContinuousLayout;
- ((JComponent)this).firePropertyChange("continuousLayout", oldCD, newContinuousLayout);
- }
-
- public void setDividerLocation(double proportionalLocation) {
- if (!(proportionalLocation < (double)0.0F) && !(proportionalLocation > (double)1.0F)) {
- if (this.getOrientation() == 0) {
- this.setDividerLocation((int)((double)(((JComponent)this).getHeight() - this.getDividerSize()) * proportionalLocation));
- } else {
- this.setDividerLocation((int)((double)(((JComponent)this).getWidth() - this.getDividerSize()) * proportionalLocation));
- }
-
- } else {
- throw new IllegalArgumentException("proportional location must be between 0.0 and 1.0.");
- }
- }
-
- public void setDividerLocation(int location) {
- SplitPaneUI ui = this.getUI();
- if (ui != null) {
- ui.setDividerLocation(location);
- }
-
- }
-
- public void setDividerSize(int newSize) {
- int oldSize = this.dividerSize;
- if (oldSize != newSize) {
- this.dividerSize = newSize;
- ((JComponent)this).firePropertyChange("dividerSize", oldSize, newSize);
- }
-
- }
-
- public void setLastDividerLocation(int newLastLocation) {
- int oldLocation = this.lastDividerLocation;
- this.lastDividerLocation = newLastLocation;
- ((JComponent)this).firePropertyChange("lastDividerLocation", oldLocation, newLastLocation);
- }
-
- public void setLeftComponent(Component comp) {
- if (comp == null) {
- if (this.leftComponent != null) {
- this.remove(this.leftComponent);
- this.leftComponent = null;
- }
- } else {
- ((Container)this).add(comp, "left");
- }
-
- }
-
- public void setOneTouchExpandable(boolean newValue) {
- boolean oldValue = this.oneTouchExpandable;
- this.oneTouchExpandable = newValue;
- ((JComponent)this).firePropertyChange("oneTouchExpandable", oldValue, newValue);
- ((Component)this).repaint();
- }
-
- public void setOrientation(int orientation) {
- if (orientation != 0 && orientation != 1) {
- throw new IllegalArgumentException("JSplitPane: orientation must be one of JSplitPane.VERTICAL_SPLIT or JSplitPane.HORIZONTAL_SPLIT");
- } else {
- int oldOrientation = this.orientation;
- this.orientation = orientation;
- ((JComponent)this).firePropertyChange("orientation", oldOrientation, orientation);
- }
- }
-
- public void setRightComponent(Component comp) {
- if (comp == null) {
- if (this.rightComponent != null) {
- this.remove(this.rightComponent);
- this.rightComponent = null;
- }
- } else {
- ((Container)this).add(comp, "right");
- }
-
- }
-
- public void setTopComponent(Component comp) {
- this.setLeftComponent(comp);
- }
-
- public void setUI(SplitPaneUI ui) {
- if ((SplitPaneUI)super.ui != ui) {
- super.setUI(ui);
- ((Container)this).invalidate();
- }
-
- }
-
- public void updateUI() {
- this.setUI((SplitPaneUI)UIManager.getUI(this));
- ((Container)this).invalidate();
- }
- }
-